import cv2
import os

# 创建文件夹保存图像序列
output_folder = "./modi_tracker/shoulders_frames/"
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# 读取视频
cap = cv2.VideoCapture("./modi_tracker/shoulders.mp4")
frame_count = 0

# 保存图像序列
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break  # 如果帧读取失败，退出循环

    # 保存帧为图像文件
    frame_filename = os.path.join(output_folder, f"frame_{frame_count:04d}.jpg")
    cv2.imwrite(frame_filename, frame)
    frame_count += 1

# 释放VideoCapture对象
cap.release()

# 打印保存完成信息
print(f"Saved {frame_count} frames to {output_folder}")
